<template>
    <div>
        <div style='margin:10px 0px'>
            <el-button-group>
                <el-button type='primary' @click='create' icon='el-icon-edit'>创建渠道商</el-button>
            </el-button-group>
        </div>
        <list ref='list' init show-selection>
            <el-table-column slot='column' label='操作' fixed='right' align='center' width='210'>
                <template slot-scope='{row}'>
                    <el-button  size='mini'  type="success"  @click='apply(row)'>授权</el-button>
                    <el-button  size='mini'  type="primary"  @click='edit(row)'>修改</el-button>
                    <el-button  size='mini'  type="danger"  @click='del(row)'>删除</el-button>
                </template>
            </el-table-column>
        </list>
        <edit-dialog ref='editDialog' @updated='reload'></edit-dialog>
        <menuList ref='menuList' @updated='apply'></menuList>
    </div>
</template>

<script>
  import list       from '@/components/api/channel/list'
  import editDialog from '@/components/api/channel/editDialog'
  import menuList   from '@/components/api/auth/authTree'

  export default {
    components:{
      list,
      editDialog,
      menuList
    },
    data(){
      return {

      }
    },
    computed:{
      //表单是否是编辑状态
      isFormEdit(){
        return this.form.id!=null
      }
    },
    mounted(){

    },
    methods:{
      exportExcel(){
        this.$refs.list.exportExcel()
      },
      create(){
        this.$refs.editDialog.open().then(that=>{

        })
      },
      edit(row){
        this.$refs.editDialog.open().then(that=>{
          that.initData(row)
        })
      },
      //删除
      del(row){
        this.$refs.list.del(row)
      },
      openSummaryListDialog(){
        this.$refs.summaryListDialog.open({ hasDelivery:1,toInvoice:1})
      },
      reload(){
        this.$refs.list.reload()
      },
      apply(row){
        this.$refs.menuList.initData(row)
        this.$refs.menuList.open()
      },
      print({row}){
        this.$refs.printLabel.open().then(that=>{
          that.getData({ids:row.id})
        })
      },
      printBatch(){

        let ids = this.$refs.list.selectionList.map(d=>{
          return d.id
        })
        this.$refs.printLabel.open().then(that=>{
          that.getData({ids:ids.join(',')})
        })
      },
      copy({row}){
        this.$refs.editDialog.open().then(that=>{
          that.create().then(res=>{
            let copyData = this.$commonJs.obj.copyByKey(row,['model','company_id','supplier_name','buy_date','price','amount','sn','remarks'])
            that.assign(copyData).clearValidate()
          })
        })
      },
      test2(){
        this.$refs.list.$refs.tableList.clearSelection()
      }
    }
  }
</script>
